home *** CD-ROM | disk | FTP | other *** search
/ SGI Networker 4.2.9 / Networker 4.2.9 for IRIX 6.2, 6.3 and 6.4.img / dist / networker4.idb / etc / nsrdmo.sh.z / nsrdmo.sh
Linux/UNIX/POSIX Shell Script  |  1997-07-08  |  13KB  |  562 lines

  1. #!/bin/sh
  2. #
  3. # @(#)nsrdmo.sh 1.7 96/12/20 Copyright (c) 1996, Legato Systems, Inc.
  4. #
  5. # All rights reserved.
  6. #
  7. # nsrdmo
  8. #
  9. # This script is part of the Database Module for Oracle.
  10. # Modification of this script should be done with care and only after reading
  11. # the administration manual included with this product.
  12. #
  13. # This script should only be run as part of a scheduled savegroup.
  14. #
  15. # Returns 0 on success; 1 on failure.
  16. #
  17.  
  18. #
  19. # Configuration variables, modifiable by users.
  20. #
  21.  
  22. #
  23. # Variable: OBK_HOME
  24. # Default value: site specific
  25. # Description: Specifies where the Enterprise Backup Utility is installed.
  26. # This variable must be configured in order to locate the obackup executable
  27. #
  28. OBK_HOME=
  29.  
  30. #
  31. # Variables: BRD_TOT_TIME, BRD_SAMP_TIME, BRD_ERR_TIME, BRD_RETRIES 
  32. # Description: The noted environment variables allow the user to 
  33. # configure the EBU Instance Manager (brd).  The default settings for these
  34. # variables as specified by Oracle are not compatible with scheduled saves
  35. # from NetWorker where obackup starts a new brd process.  If brd is started
  36. # using the default values for these variables then savegrp will appear to
  37. # appear to hang before backing up the indexes.  The following settings
  38. # will prevent the described behaviour by causing brd to exit seconds after
  39. # the backup is completed.  Consult the Oracle7 Enterprise Backup Utility 
  40. # Administrator's Guide Release 2.0 page 6-4 for more information about
  41. # these variables.
  42. #
  43.  
  44. #
  45. # Variable: BRD_TOT_TIME
  46. # Default value: 300
  47. # Oracle Default value: 172800
  48. # Description: Once the Instance Manager (brd) becomes idle, it will wait for
  49. # BRD_TOT_TIME seconds for any activity by obackup before it exits.
  50. # Caution: setting this value too low may cause brd to exit before obackup
  51. # can establish a connection to the Backup Catalog. If this happens obackup
  52. # will fail with the following error:
  53. # OBK-2464: Internal error.  Instance Manager process was not started
  54. #
  55. BRD_TOT_TIME=300
  56.  
  57. #
  58. # Variable: BRD_SAMP_TIME
  59. # Default value: 1
  60. # Oracle Default value: 300
  61. # Description: The Instance Manager (brd) checks the Backup Catalog for any
  62. # active jobs in the interval of BRD_SAMP_TIME seconds.
  63. #
  64. BRD_SAMP_TIME=1
  65.  
  66. #
  67. # Variable: BRD_ERR_TIME
  68. # Default value: 1
  69. # Oracle Default value: 900
  70. # Description: If the Instance Manager (brd) detects an error it waits
  71. # BRD_ERR_TIME before retrying the catalog.
  72. #
  73. BRD_ERR_TIME=1
  74.  
  75. #
  76. # Variable: BRD_RETRIES
  77. # Default value: 1
  78. # Oracle Default value: 3
  79. # Description: The Instance Manager (brd) looks for active jobs BRD_RETRIES
  80. # number of times before going to sleep.
  81. #
  82. BRD_RETRIES=1
  83.  
  84. # Variable: PATH
  85. # Default value: platform dependent
  86. # Set up PATH environment variable.  This must be configured to include
  87. # path to the NetWorker program "mminfo" and /usr/bin.
  88. # This variable must be configured to locate the correct executables
  89. #
  90. # HP-UX 10.x
  91. #PATH=/opt/networker/bin:/usr/bin
  92. # HP-UX 9.x
  93. #PATH=/usr/networker/bin:/usr/bin
  94. # Solaris
  95. #PATH=/bin:/usr/sbin:/usr/bin
  96. # AIX
  97. #PATH=/usr/bin
  98. # All Platforms
  99. PATH=/bin:/usr/sbin:/usr/bin:/opt/networker/bin:/usr/networker/bin
  100.  
  101. # For HP-UX only
  102. # Variable: SHLIB_PATH
  103. # Default value: /usr/lib
  104. # obackup requires this variable to be set in order to locate the libobk.sl
  105. # shared library.
  106. # This variable should be configured on HP-UX systems.
  107. #
  108. SHLIB_PATH=/usr/lib
  109.  
  110. #
  111. # Variable: PRECMD
  112. # Default value: NONE
  113. # Description: This variable can be used to run a command before oracle
  114. # backups.  
  115. # The pre command must return a non zero exit code if it fails.  It is
  116. # the resposibility of the script writer to ensure that the script 
  117. # returns the proper exit code.  Please refer chapter 5 of the BusinesSuite
  118. # Module for Oracle Administrator's Guide UNIX Version for templates and
  119. # examples.
  120. # Setting this variable is optional.
  121. #
  122. PRECMD=
  123.  
  124. #
  125. # Variable: POSTCMD
  126. # Default value: NONE
  127. # Description: This variable can be used to run a command after oracle
  128. # backups have completed. 
  129. # The post command must return a non zero exit code if it fails.  It is
  130. # the resposibility of the script writer to ensure that the script 
  131. # returns the proper exit code.  Please refer chapter 5 of the BusinesSuite
  132. # Module for Oracle Administrator's Guide UNIX Version for templates and
  133. # examples.
  134. # Setting this variable is optional.
  135. #
  136. POSTCMD=
  137.  
  138. #
  139. # Variable: NSR_DATA_VOLUME_POOL
  140. # Default value: none
  141. # Description: If this variable is set to name a media pool, then database
  142. # backups will be directed to the named media pool.
  143. # If not set DMO will use the "Default" pool.
  144. # Setting this variable is optional.
  145. #
  146. NSR_DATA_VOLUME_POOL=
  147.  
  148.  
  149. #
  150. # Variable: NSR_NO_BUSY_ERRORS
  151. # Default value: FALSE
  152. # Description: If this variable is set to a value of TRUE then DMO will
  153. # will fail immediately if it encounters a busy server while initializing
  154. # the session.
  155. # If this variable is not set DMO will fail immediately
  156. # Setting this variable is optional.
  157. #
  158. NSR_NO_BUSY_ERRORS=FALSE
  159.  
  160.  
  161. #
  162. # Variable: NSR_CHECKSUM
  163. # Default value: TRUE
  164. # Description: This environment variable specifies checksumming
  165. # is performed on the data.
  166. # If this variable is not set DMO will use checksumming by default.
  167. # Setting this variable is optional.
  168. #
  169. NSR_CHECKSUM=TRUE
  170.  
  171. #
  172. # Variable: NSR_ENCRYPTION
  173. # Default value: FALSE
  174. # Description: This environment variable specifies encryption
  175. # is performed on the data.
  176. # If this variable is not set DMO will not use encryption by default.
  177. # Setting this variable is optional.
  178. #
  179. NSR_ENCRYPTION=FALSE
  180.  
  181. #
  182. # Variable: NSR_COMPRESSION
  183. # Default value: FALSE
  184. # Description: This environment variable specifies compression
  185. # is performed on the data.
  186. # If this variable is not set DMO will not use compression by default.
  187. # Setting this variable is optional.
  188. #
  189. NSR_COMPRESSION=FALSE
  190.  
  191. #
  192. # Variable: NSR_DEBUG_FILE
  193. # Default value: none
  194. # Description: To enable debugging output for DMO set the following to 
  195. # an appropriate path and file name.  
  196. # Setting this variable is for debugging purposes only 
  197. #
  198. #NSR_DEBUG_FILE=
  199.  
  200. #
  201. # Not Supported
  202. # Variable: OBK_DEVDBG
  203. # Default value: none
  204. # Description: Set as instructed by Technical Support.
  205. # Setting this variable is for debugging purposes only 
  206. #OBK_DEVDBG=0x00000000
  207.  
  208. #
  209. # Shell and environment variables not configured by user.
  210. #
  211. NSR_SERVER=""        # Server to backup to (passed by savegrp)
  212. echo=echo        # echo command
  213. Verbose=0        # Are we generating verbose output?
  214. Pid=0            # Which process to kill when we are cancelled
  215.  
  216. #
  217. # usage(): display correct usage for nsrdmo
  218. #
  219. usage()
  220. {
  221.     ${echo} \
  222. "This command should only be executed by savegroup."
  223.     ${echo} \
  224. "usage: $0 [<options>]
  225.     Options:
  226.     [ -BEiLnqvx ] [ -s server ] [ -N name ] [ -e expiration ]
  227.     [  -f dirfile ] [ -b pool ] [ -F file ] [ -g group ]
  228.     [ -l level ] [ -t date ] [ -m masquerade ] [ -W width ] [ path ... ]
  229.  
  230. For an explanation of all options, see the save(8) man page.
  231. "
  232.     exit 1
  233. }
  234.  
  235.  
  236. #
  237. # Run the pre-processing command.  This can be used to shut down
  238. # a database.
  239. #
  240. run_precmd()
  241. {
  242.     if [ "${PRECMD}" = "" ]; then
  243.         return 0
  244.     fi
  245.  
  246.     vecho
  247.     vecho "Executing pre-processing command '${PRECMD}' at `date`"
  248.     vecho
  249.  
  250.     ${PRECMD}
  251.     return_status=$?
  252.  
  253.     vecho
  254.     vecho "Pre-processing command '${PRECMD}' finished at `date`"
  255.     vecho
  256.  
  257.     return $return_status
  258. }
  259.  
  260. #
  261. # Run the post-processing command.  This can be used to start a database.
  262. #
  263. #
  264. run_postcmd()
  265. {
  266.     if [ "${POSTCMD}" = "" ]; then
  267.         return 0
  268.     fi
  269.  
  270.     vecho
  271.     vecho "Executing post-processing command '${POSTCMD}' at `date`"
  272.     vecho
  273.  
  274.     ${POSTCMD}
  275.     return_status=$?
  276.  
  277.     vecho
  278.     vecho "Post-processing command '${POSTCMD}' finished at `date`"
  279.     vecho
  280.  
  281.     return $return_status
  282. }
  283.  
  284. #
  285. # Process arguments supplied by savegrp.  Must handle any arguments save(8)
  286. # accepts.
  287. #
  288. # Sample list of arguments
  289. # save -s empire -g Default -n -LL -m empire -l full -W78 -N /usr /usr
  290. #
  291. processargs()
  292. {
  293. while [ $# -gt 0 ]; do
  294.     case "$1" in
  295.     -s )    # Specify server
  296.         NSR_SERVER=$2
  297.         shift
  298.         shift
  299.         ;;
  300.     -B )    # Force connecting directory information
  301.         Bflag=y
  302.         shift
  303.         ;;
  304.     -E )    # Estimate save set size
  305.         Eflag=y
  306.         shift
  307.         ;;
  308.     -i )    # Ignore any directives
  309.         iflag=y
  310.         shift
  311.         ;;
  312.     -LL )    # Force local backup and cause extra line to be printed
  313.         LLflag=y
  314.         shift
  315.         ;;
  316.     -n)    # No save
  317.         nflag=y
  318.         shift
  319.         ;;
  320.     -q )    # Quiet
  321.         qflag=y
  322.         shift
  323.         ;;
  324.     -v )    # Verbose
  325.         Verbose=1
  326.         shift
  327.         ;;
  328.     -N )    # Save set name 
  329.         Saveset_name=$2
  330.         shift
  331.         shift
  332.         ;;
  333.     -e )    # Specify alternate expiration time
  334.         NSR_SAVESET_EXPIRATION=$2
  335.         shift
  336.         shift
  337.         ;;
  338.     -f )    # Specify directives
  339.         Directives=$2
  340.         shift
  341.         shift
  342.         ;;
  343.     -b )    # Specify pool
  344.         NSR_DATA_VOLUME_POOL=$2
  345.         shift
  346.         shift
  347.         ;;
  348.     -F )    # Specify file for modification time comparison (not used)
  349.         Directives=$2
  350.         shift
  351.         shift
  352.         ;;
  353.     -g )    # Specify group
  354.         Group=$2
  355.         shift
  356.         shift
  357.         ;;
  358.     -l )    # Specify level
  359.         Level=$2
  360.         shift
  361.         shift
  362.         ;;
  363.     -t )    # Specify time for comparison
  364.         Comparison_time=$2
  365.         shift
  366.         shift
  367.         ;;
  368.     -m )    # Masquerade as another program
  369.         Masquerade=$2
  370.         shift
  371.         shift
  372.         ;;
  373.     -W )    # Specify width of output
  374.         Output_width=$2
  375.         shift
  376.         shift
  377.         ;;
  378.     *)    # Name of the obackup script
  379.         obk_commands=$1
  380.         shift
  381.         ;;
  382.     esac
  383. done
  384. }
  385.  
  386. #
  387. # Make sure all environment variables are exported.
  388. #
  389. export_environment_variables()
  390. {
  391.     export NSR_SERVER
  392.     export NSR_COMPRESSION
  393.     export NSR_ENCRYPTION
  394.     export NSR_CHECKSUM
  395.     export NSR_SAVESET_EXPIRATION
  396.     export OBK_HOME
  397.     export PATH
  398. #    export NSR_DATA_VOLUME_POOL
  399.  
  400. # The following variables control EBU Instance Manager operation
  401.     export BRD_TOT_TIME
  402.     export BRD_SAMP_TIME
  403.     export BRD_ERR_TIME
  404.     export BRD_RETRIES
  405.  
  406. # The following variable is required on HP-UX
  407.     export SHLIB_PATH
  408.  
  409. # The following variables are for debugging only.
  410. #    export NSR_DEBUG_FILE 
  411. #    export OBK_DEVDBG
  412. }
  413.  
  414. #
  415. # backup_oracle: run obackup to backup the oracle database
  416. # The particulars of the backup are contained in the obackup 
  417. # command script which is passed to obackup
  418. # nsrobkstart must be on the PATH.
  419. #
  420. backup_oracle()
  421. {
  422.  
  423. #    $OBK_HOME/bin/obackup $obk_commands
  424.     nsrobkstart $obk_commands &
  425.      Pid=$!
  426.      wait $Pid
  427.     obackup_status=$?
  428.  
  429.     if [ $obackup_status != 0 ]; then
  430.         echo "obackup returned status of "$obackup_status
  431.     fi
  432. }
  433.  
  434. #
  435. # Echo the arguments only if in verbose mode.
  436. #
  437. vecho()
  438. {
  439.     if [ $Verbose -gt 0 ]; then
  440.         echo $*
  441.     fi
  442. }
  443.  
  444. #
  445. # Display output exactly like save does to keep savegroup happy. 
  446. # displays size information for database backups.  
  447. #
  448. display_summary()
  449. {
  450.     Hostname=`uname -n`
  451.         /usr/bin/echo "$Hostname: Oracle Backup Status             level=full,        \c"
  452.        mminfo -s $NSR_SERVER -q"savetime>=$Start_time,savetime<=$End_time" -r "name,totalsize(1),nfiles(1)" | \
  453. awk '\
  454. BEGIN { total_kb = 0; total_mb = 0; total_files = 0; files_str = "file" } \
  455. { \
  456.         if ( $3 == "KB" ) { \
  457.                total_kb += $2 \
  458.        } else { \
  459.                total_mb += $2 \
  460.        } \
  461.        total_files += $4 \
  462. } \
  463. END { \
  464.        if (total_files > 1) {  \
  465.                files_str = "files"  \
  466.        } else {  \
  467.                files_str = "file" \
  468.        } \
  469.         if (total_kb > 1000) { \
  470.                total_mb += (total_kb / 1000) \
  471.        } \
  472.         if (total_mb > 0) {  \
  473. printf "%d.%d MB 00:00:00  %d %s\n", total_mb, total_kb % 1000, total_files, files_str \
  474.        } else {  \
  475. printf "%d KB 00:00:00  %d %s\n", total_kb, total_files, files_str  \
  476.        } \
  477. }'
  478.  
  479.     return 0
  480.  
  481. }
  482.  
  483. #
  484. # Handle cancel signals sent by savegrp when user stops the group.
  485. # obackup likes to be cancelled with a SIGHUP
  486. #
  487. handle_signal()
  488. {
  489.     if [ $Pid != 0 ]; then
  490.         kill -1 $Pid
  491.     fi
  492.     exit 1
  493. }
  494.  
  495. #
  496. # The main portion of this shell.
  497. #
  498. # Process arguments, export environment
  499. # Execute a pre-command (if any)
  500. # Execute obackup backup
  501. # Execute a post-command
  502. # Display save output
  503.  
  504. processargs $*
  505.  
  506. #
  507. # Make sure we respond to savegrp cancellations.
  508. #
  509. trap handle_signal 2 15
  510.  
  511. #
  512. # Export all environment variables.
  513. #
  514. export_environment_variables
  515.  
  516. #
  517. # Handle pre-processing
  518. #
  519. run_precmd
  520. precmd_status=$?
  521. if [ $precmd_status != 0 ]; then
  522.     echo "Pre-processing command failed.  Ending session."
  523.     exit 1
  524. else
  525.     vecho "Pre-processing command succeeded."
  526. fi
  527.  
  528. #
  529. # Handle database backup
  530. #
  531. Start_time=`date`
  532. backup_oracle
  533. End_time=`date`
  534.  
  535. #
  536. # handle post-processing
  537. #
  538. run_postcmd
  539. postcmd_status=$?
  540. if [ $postcmd_status != 0 ]; then
  541.     echo "Post-processing command failed.  Ending session."
  542.     if [ $obackup_status != 0 ]; then
  543.         exit $obackup_status
  544.     else
  545.         exit 1
  546.     fi
  547. else
  548.     vecho "Post-processing command succeeded."
  549.     if [ $obackup_status != 0 ]; then
  550.         exit $obackup_status
  551.     fi
  552. fi
  553.  
  554. #
  555. # Display summary for savegroup
  556. # Only displays if pre-command, obackup, and post-command were all
  557. # successful.
  558. #
  559. display_summary
  560.  
  561. exit 0
  562.